﻿/*----------------------------------------------------------------
//Copyright (C) 2012 赵国伟
//文件功能描述：资讯管理客户端脚本
//创建人：赵国伟
//生成时间：2012/03/17 16:15:00
//----------------------------------------------------------------*/

var NewsID = 0;
var AjaxServerUrl = "/Manage/AS/NewsCommon.aspx";
var SelectOptionOfCategory = "";
var ModelOfNews;


function GoToSearch() {
    var url = "NewsManage.aspx?";
    url += "keyWords=" + escape($("#txtKeyWordsOfSearch").val().trim());
    url += "&CategoryID=" + $("#ddlCategoryIDOfSearch").val();
    url += "&StartDate=" + $("#txtStartDateOfSearch").val();
    url += "&EndDate=" + $("#txtEndDateOfSearch").val();
    url += "&Status=" + escape($("#ddlStatusOfSearch").val());
    url += "&Sorts=" + $("#ddlSortsOfSearch").val();
    location.href = url;
}

function Init() {
    NewsID = 0;
}

function CheckForm() {
    if ($("#txtTitle").val() == "") {
        alert("系统提示：请输入资讯标题！");
        $("#txtTitle").focus();
        return false;
    }
    if ($("#ddlCategoryID").val() == "") {
        alert("系统提示：请选择资讯类别！");
        $("#ddlCategoryID").focus();
        return false;
    }
    if (!IsNumber($("#txtOrderValue").val())) {
        alert("系统提示：排序值必须为数字！");
        $("#txtOrderValue").focus();
        return false;
    }
    /*
    if (GetEditorHTMLContents("txtBody") == "") {
        alert("系统提示：请输入资讯内容！");
        $("#txtBody").focus();
        return false;
    }
    */
    return true;
}

function Save() {
   
    $("#btnSave").attr("disabled", true);
    if (!CheckForm()) {
        $("#btnSave").attr("disabled", false);
        return;
    }

    var newsInfo = clone(ModelOfNews);
    newsInfo._newsid = NewsID;
    newsInfo._title = $("#txtTitle").val();
    newsInfo._colors = $("#ddlColor").val();
    newsInfo._categoryid = $("#ddlCategoryID").val();
    newsInfo._ordervalue = $("#txtOrderValue").val();
    newsInfo._status = $("#ddlStatus").val();

    if ($("#chkIsTop").attr("checked") == true)
        newsInfo._istop = 1;
    newsInfo._jumpurl = $("#txtJumpUrl").val();
    if (newsInfo._jumpurl == "")
        newsInfo._jumpurl = "http://";
    newsInfo._createdate = "/Date(" + CurrentDateStringToUTC() + ")/";
    newsInfo._lastmodifydate = "/Date(" + CurrentDateStringToUTC() + ")/";
    var url = AjaxServerUrl + "?Action=SaveNews";

    var postData = "jsonData=" + JSON.stringify(eval(newsInfo));
    postData += "&Content=" + escape(GetEditorHTMLContents("txtBody"));
    AjaxPostEx(url, "btnSave", postData);  //更新数据；
    $("#btnSave").attr("disabled", false);
}

function BindNewsToForm() {
    var url = AjaxServerUrl + "?action=GetNews&NewsID=" + NewsID + "&tttt=" + Math.random();
    $.ajax(
    {
        type: "Get",
        url: url,
        dataType: "json",
        success: function (data) {
            $("#txtTitle").val(data.news._title);
            $("#ddlColor").val(data.news._colors);
            $("#ddlCategoryID").val(data.news._categoryid);
            if (data.news._istop == 1)
                $("#chkIsTop").attr("checked", true);
            $("#txtOrderValue").val(data.news._ordervalue);
            $("#ddlStatus").val(data.news._status);
            $("#txtJumpUrl").val(data.news._jumpurl);
            $("#txtBody").val(data.news._newscontent);
        }
    });
}


function Add() {
    Init();
    GetPopupDiv(700, 800, "#e2e2e2", "添加资讯", GetNewsHTMLForm());
    GetEditor("txtBody", "98%");
}

function Edit(id) {
    Init();
    NewsID = id;
    GetPopupDiv(700, 800, "#e2e2e2", "编辑资讯", GetNewsHTMLForm());
    GetEditor("txtBody", "98%");
    BindNewsToForm();
}

///执行删除；
function Delete(id) {
    if (!confirm("提示：您确定要删除该条资讯吗？"))
        return;
    AjaxGet(AjaxServerUrl + "?Action=DeleteNews&NewsID=" + id);
}

function GetNewsHTMLForm() {
    var html = new Array();
    html.push("<form>");
    html.push("<table width=\"700\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"table\">");
    html.push("  <tr>");
    html.push("    <td colspan=\"2\" class=\"TableHeadRow\">&gt;&gt;资讯信息</td>");
    html.push("  </tr>");
    
    html.push("  <tr>");
    html.push("    <td width=\"70\" align=\"right\">标题：</td>");
    html.push("    <td >");
    html.push("<select name=\"ddlColor\" id=\"\ddlColor\">");
    html.push("<option value=\"\">--标题颜色--</option>");
    html.push("<option value=\"red\" style=\"background-color:red;\" ></option>");
    html.push("<option value=\"blue\" style=\"background-color:blue;\" ></option>");
    html.push("</select>");
    html.push("<input name=\"txtTitle\" type=\"text\" id=\"txtTitle\" size=\"70\" class=\"border6\"> ");
    html.push("      <span class=\"red\">*</span> </td>");
    html.push("  </tr>");
    html.push("  <tr>");
    html.push("    <td align=\"right\">类别：</td>");
    html.push("    <td>");
    html.push("<select name=\"ddlCategoryID\" id=\"\ddlCategoryID\">");
    html.push("<option value=\"\">--请选择--</option>");
    html.push(SelectOptionOfCategory);
    html.push("</select><span class=\"red\">*</span> ");
    html.push("</td>");
    html.push("  </tr>");

    html.push("  <tr>");
    html.push("    <td align=\"right\"  >排序值：</td>");
    html.push("    <td  align=\"left\" ><input name=\"txtOrderValue\" type=\"text\" id=\"txtOrderValue\" class=\"border6\" size=\"5\" value=\"0\">");
    html.push("      <span class=\"red\">*</span></td>");
    html.push("  </tr>");

    html.push("  <tr>");
    html.push("    <td align=\"right\">&nbsp;</td>");
    html.push("    <td> <label><input type=\"checkbox\" id=\"chkIsTop\" >是否置顶</label>");
    html.push("   </td>");
    html.push("  </tr>");

    html.push("  <tr>");
    html.push("    <td align=\"right\">跳转URL：</td>");
    html.push("    <td> <input name=\"txtJumpUrl\" type=\"text\" id=\"txtJumpUrl\" class=\"border6\" size=\"80\" value=\"http://\">");
    html.push("   </td>");
    html.push("  </tr>");

    html.push("  <tr>");
    html.push("    <td align=\"right\">内容：</td>");
    html.push("    <td><textarea name=\"txtBody\" cols=\"50\" rows=\"5\" id=\"txtBody\"></textarea> </td>");
    html.push("  </tr>");
    html.push("  <tr>");
    html.push("    <td align=\"right\">状态：</td>");
    html.push("    <td><select name=\"ddlStatus\" id=\"\ddlStatus\">");
    html.push("<option value=\"正用\">正用</option>");
    html.push("<option value=\"停用\">停用</option>");
    html.push("    </select>    </td>");
    html.push("  </tr>");
    html.push("  <tr>");
    html.push("    <td align=\"right\">&nbsp;</td>");
    html.push("    <td><input name=\"btnSave\" type=\"button\" id=\"btnSave\" value=\" 保 存 \" onClick=\"Save();\" class=\"btn2\" >");
    html.push("    <input name=\"btnReset\" type=\"reset\" id=\"btnReset\" value=\" 重 置 \"  class=\"btn2\">");
    html.push("    <input name=\"btnClose\" type=\"button\" id=\"btnClose\" value=\"关闭窗口\" onClick=\"yesOther(false)\"  class=\"btn2\"></td>");
    html.push("  </tr>");
    html.push("</table>");
    html.push("</form>");
    return html.join("");
}